<script setup>
import {ref} from "vue"
import { httpRequest } from "../../utils/http"
const recordList = ref([])
const geShopKa = async() => {
    uni.showLoading({
        title: '请稍后',
        mask: false
    })
    const res = await httpRequest('/api/getShopKa','POST',{
        businessId:uni.getStorageSync('business').businessId
    })
    uni.hideLoading()
    console.log(res);
    recordList.value = res.data
}
geShopKa()
const daysPerYear = 24*60*60*365*1000
const formatTimestamp = (timestamp) => {
  const date = new Date(timestamp);
  const year = date.getFullYear();
  const month = ('0' + (date.getMonth() + 1)).slice(-2);
  const day = ('0' + date.getDate()).slice(-2);
  const hours = ('0' + date.getHours()).slice(-2);
  const minutes = ('0' + date.getMinutes()).slice(-2);
  const seconds = ('0' + date.getSeconds()).slice(-2);
  const formattedTime = `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
  return formattedTime;
}
</script>

<template>
  <view class="page">
    <view class="kong" v-if="!recordList.length">
        <image class="kong-img" src="https://www.diandianyouke.site:801/fileDataBase/static/stag/static/img/state_empty.png" mode="" />
        <text class="kong-text">暂无充值记录</text>
    </view>
    <view v-else style="padding: 30rpx;box-sizing: border-box;">
        <view class="item" v-for="item in recordList" :key="item.id">
            <view class="top">
                <view class="kami">
                    <image style="width: 32rpx;height: 32rpx;" src="https://www.diandianyouke.site:801/fileDataBase/static/stag/static/img/ursse_cz_icon_czkmi.png" mode="" />
                    <text>卡密</text>
                </view>
                <text style="font-size: 24rpx;color: rgb(144,147,153);">{{item.kaMi}}</text>
            </view>
            <view>
                <view class="box">
                    <text class="box-left">店铺</text>
                    <text class="box-right">{{item.shop.shopName}}</text>
                </view>
                <view class="box">
                    <text class="box-left">类型</text>
                    <text class="box-right">{{ item.productName }}</text>
                </view>
                <view class="box">
                    <text class="box-left">状态</text>
                    <text class="box-right">成功</text>
                </view>
                <view class="box">
                    <text class="box-left">充值时间</text>
                    <text class="box-right">{{formatTimestamp(item.endDate - daysPerYear)}}</text>
                </view>
            </view>
        </view>
    </view>
  </view>
</template>

<style lang="scss" scoped>
    .page{
        min-height: 1500rpx;
    .kong{
      box-sizing: border-box;
      position: absolute;
      width: 100%;
      height: 100%;
      background-color: #fff;
      padding: 0 70rpx;
      text-align: center;
      overflow: hidden;
      .kong-img{
        width: 610rpx;
        height: 368rpx;
        margin-top: 132rpx;
        margin-bottom: 42rpx;
      }
      .kong-text{
        font-size: 32rpx;
        color: rgb(144,147,153);
      }
    }
    .item{
        padding: 0 30rpx 36rpx;
        box-sizing: border-box;
        background-color: #fff;
        border-radius: 24rpx;
        margin-bottom: 30rpx;
        .top{
            height: 112rpx;
            width: 100%;
            display: flex;
            justify-content: space-between;
            align-items: center;
            border-bottom: 1px solid rgb(235,238,245);
            margin-bottom: 36rpx;
            .kami{
                display: flex;
                align-items: center;
                font-size: 30rpx;
                color: rgb(69,70,74);
            }
        }
        .box{
            width: 100%;
            display: flex;
            justify-content: space-between;
            font-size: 30rpx;
            margin-bottom: 36rpx;
            &:nth-last-child(1){
                margin-bottom: 0;
            }
            .box-left{
                color: rgb(144,147,153);
            }
            .box-right{
                color: rgb(69,70,74);
            }
        }
    }
    }
</style>
